home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / misc / comparezones < prev    next >
Encoding:
Text File  |  1996-10-25  |  1.8 KB  |  102 lines

  1. #! /bin/perl
  2.  
  3. # This script compares the contents of two zone files, excluding the
  4. # second line (serial) and all comments. This is a temporary tool for
  5. # giving me some confidence before installing my new zone-generating
  6. # script.
  7. #
  8. # Philip Hazel, September 2, 1993.
  9.  
  10.  
  11.  
  12. # ******** Get next non-comment, non-blank line ********
  13.  
  14. sub next_one{
  15. for (;;)
  16.   {
  17.   return 0 if (!($one = <ONE>));
  18.   last if substr($one, 0, 1) ne ";" && $one !~ /^\s*$/;
  19.   }   
  20. return 1;
  21. }
  22.  
  23. sub next_two{
  24. for (;;)
  25.   {
  26.   return 0 if (!($two = <TWO>));
  27.   last if substr($two, 0, 1) ne ";" && $two !~ /^\s*$/;
  28.   }   
  29. return 1;
  30. }
  31.  
  32.  
  33. # ******** Compare two lines ********
  34.  
  35. sub check{
  36. @fields_one = split(/\s+/, $one);
  37. @fields_two = split(/\s+/, $two);
  38.  
  39. if ($#fields_one != $#fields_two)
  40.   {
  41.   print "** Different number of fields in lines:\n";
  42.   print "** $one";
  43.   print "** $two";
  44.   die "** Giving up\n";    
  45.   }
  46.   
  47. for ($i = 0; $i <= $#fields_one; $i++)
  48.   {
  49.   if ($fields_one[$i] ne $fields_two[$i])
  50.     {
  51.     print "** Lines don't match:\n";
  52.     print "** $one";
  53.     print "** $two";
  54.     die "** Giving up\n";    
  55.     }
  56.   }
  57. }    
  58.          
  59.  
  60.  
  61. # ******** The Main Program ********
  62.  
  63. open(ONE, $ARGV[0]) || die "$ARGV[0] failed to open";
  64. open(TWO, $ARGV[1]) || die "$ARGV[1] failed to open";
  65.  
  66. # Get the first lines & check them
  67.  
  68. do next_one();
  69. do next_two();
  70. do check();
  71.  
  72. # Skip the second lines
  73.  
  74. do next_one();
  75. do next_two();
  76.  
  77. # Do the rest of the file
  78.  
  79. for (;;)
  80.   {
  81.   if (! &next_one())
  82.     {
  83.     if (&next_two())
  84.       {
  85.       print "** First file ends before the second\n";
  86.       die "** Giving up\n";  
  87.       }
  88.     else { last; }      
  89.     }  
  90.     
  91.   else
  92.     {
  93.     if (! &next_two())
  94.       {
  95.       print "** Second file ends before the first\n";
  96.       die "** Giving up\n";  
  97.       }
  98.     else { do check(); }
  99.     }
  100.   }               
  101.  
  102.